﻿#include "flashitem.h"
#include<QPainter>
FlashItem::FlashItem(QObject *parent)
    : QObject{parent}
{
    flash=true;
    setFlag(ItemIsMovable);//设置图元可以用鼠标移动
    startTimer(1000);
}
QRectF FlashItem::boundingRect()const//定义图元边界
{
    qreal adjust=2;
    return QRectF(-10-adjust,-10-adjust,43+adjust,43+adjust);
}
void FlashItem::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget)
{
    painter->setPen(Qt::NoPen);//闪烁图元的阴影区不绘制边线
    painter->setBrush(Qt::darkGray);//设置阴影区为深灰
    painter->drawEllipse(-7,-7,40,40);//阴影区绘制
    painter->setPen(QPen(Qt::black,0));//设置椭圆区为黑色，线宽为0
    painter->setBrush(flash?(Qt::red):(QColor(rand()%256,rand()%256,rand()%256)));
    painter->drawEllipse(-10,-10,40,40);//绘制上层椭圆
}
void FlashItem::timerEvent(QTimerEvent *)
{
    flash=!flash;
    update();
}
